Imports System.Configuration
Imports System.Web.Configuration

''' <summary>
''' A singleton class that manages the providers collection
''' </summary>
Public Class $safeitemname$
	Shared Sub New()
	    Initialize()
	End Sub

	Private Shared _default As $fileinputname$DataProvider
	''' <summary>
	''' Returns the default configured data provider
	''' </summary>
	Public Shared ReadOnly Property [Default]() As $fileinputname$DataProvider
	    Get
		Return _default
	    End Get
	End Property

	Private Shared _providerCollection As $fileinputname$DataProviderCollection
	''' <summary>
	''' .Returns the provider collection
	''' </summary>
	Public Shared ReadOnly Property Providers() As $fileinputname$DataProviderCollection
	    Get
		Return _providerCollection
	    End Get
	End Property

	Private Shared _providerSettings As ProviderSettingsCollection
	Public Shared ReadOnly Property ProviderSettings() As ProviderSettingsCollection
	    Get
		Return _providerSettings
	    End Get
	End Property

	''' <summary>
	''' Reads the configuration related to the set of configured 
	''' providers and sets the default and collection of providers and settings.
	''' </summary>
	Private Shared Sub Initialize()
	    Dim configSection As $fileinputname$DataProviderConfiguration = DirectCast(ConfigurationManager.GetSection("$fileinputname$DataProvider"), $fileinputname$DataProviderConfiguration)
	    If configSection Is Nothing Then
		Throw New ConfigurationErrorsException("Data provider section is not set.")
	    End If

	    _providerCollection = New $fileinputname$DataProviderCollection()
	    ProvidersHelper.InstantiateProviders(configSection.Providers, _providerCollection, GetType($fileinputname$DataProvider))

	    _providerSettings = configSection.Providers

	    If _providerCollection(configSection.DefaultProviderName) Is Nothing Then
		Throw New ConfigurationErrorsException("Default data provider is not set.")
	    End If
	    _default = _providerCollection(configSection.DefaultProviderName)
	End Sub
End Class
